package com.owen.springboot.smartparkingms.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.owen.springboot.smartparkingms.common.model.Result;
import com.owen.springboot.smartparkingms.module.sys.entity.Config;
import com.owen.springboot.smartparkingms.module.sys.mapper.ConfigMapper;
import com.owen.springboot.smartparkingms.module.sys.service.IConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 基础配置 服务实现类
 * </p>
 *
 * @author Owen
 * @since 2022-02-25
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements IConfigService {

    @Resource
    private ConfigMapper configMapper;

    @Override
    public Result listPage(Config config) {
        IPage<Config> page = new Page(config.getPageNo(),config.getPageSize());
        QueryWrapper query = new QueryWrapper<>()
                .like("config_key ",config.getDescription())
                .or().like("config_remark",config.getDescription());
        IPage<Config> list = configMapper.selectPage(page,query);
        return Result.ok(list);
    }

    @Override
    public Object getByKey(String key) {
        QueryWrapper query = new QueryWrapper<>()
                .eq("config_value", key);
        Config config = configMapper.selectOne(query);
        if(config != null){
            return config.getConfigValue();
        }
        return null;
    }
}
